package com.game.data.vo
{
    import base.BaseVO;
    
    import com.dusk.util.ClassUtil;
    import com.game.data.constant.EquipType;
    
    public class WearEquipVO extends BaseVO
    {
        public function WearEquipVO()
        {
            super();
        }
        //武器
        public var weapon:EquipmentVO;
        //衣服
        public var cloth:EquipmentVO;
        //装饰
        public var decoration:EquipmentVO;
        //翅膀
        public var wing:EquipmentVO;
        //称号
        public var title:EquipmentVO;
        //武器套装
        public var fashionWeapon:EquipmentVO;
        //衣服套装
        public var fashionCloth:EquipmentVO;
        //翅膀套装
        public var fashionWing:EquipmentVO;
        //衣柜武器
        public var displayWeapon:EquipmentVO;
        //衣柜衣服
        public var displayCloth:EquipmentVO;
        //衣柜翅膀
        public var displayWing:EquipmentVO;
        //属性法宝
        public var attribMagicWeapon:EquipmentVO;
        //技能法宝
        public var skillMagicWeapon:EquipmentVO;
        
        public function getShowId():Object
        {
            var id:Object = {};
            id.weapon = weapon ? weapon.showId : 1;
            id.cloth = cloth ? cloth.showId : 1;
            id.wing = wing ? wing.showId : 1;
            
            id.fashionWeapon = fashionWeapon ? fashionWeapon.showId : 0;
            id.fashionCloth = fashionCloth ? fashionCloth.showId : 0;
            id.fashionWing = fashionWing ? fashionWing.showId : 0;
            
            id.displayWeapon = displayWeapon ? displayWeapon.showId : 0;
            id.displayCloth = displayCloth ? displayCloth.showId : 0;
            id.displayWing = displayWing ? displayWing.showId : 0;
            return id;
        }
        
        /**
         * 提供了基础装备的穿戴，displayEquip、skillMagicWeapon不能使用此API，需要手动赋值
         * @param vo EquipmentVO
         */
        public function putOn(vo:EquipmentVO):void
        {
            switch (vo.type)
            {
                case EquipType.ROLE_CLOTH:
                    cloth = vo;
                    break;
                case EquipType.ROLE_WEAPON:
                    weapon = vo;
                    break;
                case EquipType.ROLE_DECORATION:
                    decoration = vo;
                    break;
                case EquipType.ROLE_WING:
                    wing = vo;
                    break;
                case EquipType.ROLE_TITLE:
                    title = vo;
                    break;
                case EquipType.FASHION_CLOTH:
                    fashionCloth = vo;
                    break;
                case EquipType.FASHION_WEAPON:
                    fashionWeapon = vo;
                    break;
                case EquipType.FASHION_WING:
                    fashionWing = vo;
                    break;
                case EquipType.MAGIC_WEAPON:
                    attribMagicWeapon = vo;
                    break;
            }
        }
        
        public function takeOff(vo:EquipmentVO):void
        {
            var allType:Array = ClassUtil.getClassProperty(WearEquipVO);
            for each(var t:String in allType)
            {
                if(this[t] == vo)
                {
                    this[t] = null;
                }
            }
        }
        
        public function getEquipByType(type:String):EquipmentVO
        {
            switch (type)
            {
                case EquipType.ROLE_CLOTH:
                    return cloth;
                case EquipType.ROLE_WEAPON:
                    return weapon;
                case EquipType.ROLE_DECORATION:
                    return decoration;
                case EquipType.ROLE_WING:
                    return wing;
                case EquipType.ROLE_TITLE:
                    return title;
                case EquipType.FASHION_CLOTH:
                    return fashionCloth;
               case EquipType.FASHION_WEAPON:
                    return fashionWeapon;
                case EquipType.FASHION_WING:
                    return fashionWing;
                case EquipType.MAGIC_WEAPON:
                    return attribMagicWeapon;
            }
            return null;
        }
        
        public function getAllEquip():Array
        {
            var arr:Array = [];
            for each (var i:String in ClassUtil.getClassProperty(WearEquipVO))
            {
                arr.push(this[i]);
            }
            return  arr.filter(function(item:Object,a:*,b:*):Boolean
            {
                return item != null && item is EquipmentVO;
            });
        }
    }
}
